package com.ra.landlord;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.Index;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

/**
 * 记录房东用户的使用时长
 * 
 * @author Jerry
 *
 */
@Entity
@Table(name = "ra_landlordtracer")
public class LandlordTracer {

	private Integer id;
	
	// 房东
	private LandlordUser landlordUser;
	
	// 登录时间
	private Date loginTime;
	
	// 使用时间, 单位为秒
	private Integer spendTime;
	
	// 上次登陆时间 (查询最近一次登陆取得)
	private Date lastLoginTime;
	
	// 用户IP
	private String ip;
	
	// PC的mac地址 (使用APP时,此字段为空)
	private String mac;
	
	// PC或APP
	private String computer;
	
	private String description;

	@Id
	@GeneratedValue
	@Column(name = "tracer_id")
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name = "user_id")
	@Index(name="idx_ra_landlordtracer_user_id")
	@NotFound(action = NotFoundAction.IGNORE)
	public LandlordUser getLandlordUser() {
		return landlordUser;
	}

	public void setLandlordUser(LandlordUser landlordUser) {
		this.landlordUser = landlordUser;
	}

	@Column(name = "user_time_login")
	@Temporal(TemporalType.TIMESTAMP)
	@Index(name="idx_ra_landlordtracer_login")
	public Date getLoginTime() {
		return loginTime;
	}

	public void setLoginTime(Date loginTime) {
		this.loginTime = loginTime;
	}

	@Column(name = "user_time")
	public Integer getSpendTime() {
		return spendTime;
	}

	public void setSpendTime(Integer spendTime) {
		this.spendTime = spendTime;
	}
	
	@Column(name = "user_time_login_last")
	@Temporal(TemporalType.TIMESTAMP)
	public Date getLastLoginTime() {
		return lastLoginTime;
	}

	public void setLastLoginTime(Date lastLoginTime) {
		this.lastLoginTime = lastLoginTime;
	}

	@Column(name = "ip_login")
	public String getIp() {
		return ip;
	}

	public void setIp(String ip) {
		this.ip = ip;
	}

	@Column(name = "mac_login")
	public String getMac() {
		return mac;
	}

	public void setMac(String mac) {
		this.mac = mac;
	}

	@Column(name = "login_computer_name")
	public String getComputer() {
		return computer;
	}

	public void setComputer(String computer) {
		this.computer = computer;
	}

	@Column(name = "notes")
	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}
}
